#ifndef EASYMSGDISPATCHER_H
#define EASYMSGDISPATCHER_H
#include "libeasymsg_global.h"
#include <QMap>
#include <tr1/memory>
#include <tr1/functional>
#include <tr1/shared_ptr.h>

namespace EM {
    class EasyMsg;
}
namespace EasyMsgImp{

class EasyMsgEventHandler;
class EasyMsgCallback;

struct CallbackData{
    // hostobj 和 callback的对应关系 一个对象可以对应多个回调
    QMap<void*, QList<std::tr1::shared_ptr<EasyMsgCallback>>> callbackDataMap;
};

class LIBEASYMSGSHARED_EXPORT EasyMsgDispatcher
{
public:
    static EasyMsgDispatcher* Instance();
    void addCallback(QString msgId, void* hostobj, std::tr1::shared_ptr<EasyMsgCallback> callback);
    void removeCallback(QString msgId, void* hostObj);
    void removeCallback(void* hostObj);
    void dispatch(EM::EasyMsg* msg);
    EasyMsgEventHandler* eventHandler();
private:
    EasyMsgDispatcher();
    ~EasyMsgDispatcher();
private:
    static EasyMsgDispatcher* s_instance;
    EasyMsgEventHandler* m_eventHandler;
    QMap<QString, CallbackData> m_callbackMap;//一个消息可以被多个对象订阅
};

}
#endif // EASYMSGDISPATCHER_H
